home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / jscript.h.z / jscript.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  5.1 KB  |  204 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.               (C) 1997 Torben Weis (weis@kde.org)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.     Boston, MA 02111-1307, USA.
  19. */
  20. #ifndef JSBUILTIN_H
  21. #define JSBUILTIN_H
  22.  
  23. #include <qstring.h>
  24. #include <jsexec.h>
  25.  
  26. class KHTMLView;
  27. class JSEnvironment;
  28. class JSDocumentObject;
  29. class JSDocumentWriteFunction;
  30. class JSWindowObject;
  31. class JSWindowVarObject;
  32. class JSInstanceScope;
  33. class JSWindowArrayObject;
  34.  
  35. class JSEventHandler
  36. {
  37. public:
  38.     JSEventHandler( JSEnvironment *_env, const char *_name, const char *_code );
  39.     ~JSEventHandler();
  40.     
  41.     JSEnvironment *getJSEnvironment() { return jsEnvironment; }
  42.     const char* getName() { return name.data(); }
  43.     int exec( JSInstanceScope *_scope );
  44.     
  45. protected:
  46.     JSCode *code;
  47.     QString name;
  48.     JSEnvironment *jsEnvironment;
  49. };
  50.  
  51.  
  52. #include "html.h"
  53.  
  54. #define TYPE_JSDocumentObject 1000
  55. #define TYPE_JSWindowObject 1001
  56. #define TYPE_JSWindowVarObject 1002
  57.  
  58. #define KIND_JSWindowStatus 1
  59. #define KIND_JSWindowParent 2
  60. #define KIND_JSWindowTop 3
  61. #define KIND_JSWindowName 4
  62. #define KIND_JSWindowFrames 5
  63.  
  64. class JSWindowObject : public JSUserDefinedObject
  65. {
  66. public:
  67.     JSWindowObject( JSEnvironment *_jsenv );
  68.     virtual ~JSWindowObject();
  69.  
  70.     virtual int isA() { return TYPE_JSWindowObject; }    
  71.     virtual bool inherits( int _type )
  72.     { if ( _type == TYPE_JSWindowObject ) return TRUE;
  73.     else return JSUserDefinedObject::inherits( _type ); }
  74.  
  75.     /**
  76.      * Never delete this instance.
  77.      */
  78.     virtual void release() { if ( lock > 1 ) lock--;  }
  79.  
  80.     JSEnvironment* getJSEnvironment() { return jsEnvironment; }
  81.     
  82. protected:
  83.     /**
  84.      * The variable 'status' of the window object.
  85.      */
  86.     JSWindowVarObject *varStatus;
  87.     JSWindowVarObject *varParent;
  88.     JSWindowVarObject *varTop;    
  89.     JSWindowVarObject *varName;
  90.  
  91.     /**
  92.      * Pointer to the environment this window object belongs to.
  93.      */
  94.     JSEnvironment *jsEnvironment;
  95.  
  96.     /**
  97.      * The object 'document'
  98.      */
  99.     JSDocumentObject *jsDocumentObject;
  100.     /**
  101.      * The variable that holds the object 'document'.
  102.      */
  103.     JSVariableObject *jsDocumentVar;
  104.     /**
  105.      * The object 'frames'
  106.      */
  107.     JSWindowArrayObject *jsFramesObject;
  108.     /**
  109.      * The variable that holds the array 'frames'.
  110.      */
  111.     JSVariableObject *jsFramesVar;
  112.  
  113. };
  114.  
  115. class JSWindowArrayObject : public JSAbstractArrayObject
  116. {
  117. public:
  118.     JSWindowArrayObject( JSWindowObject *_win, int _kind );
  119.     virtual ~JSWindowArrayObject();
  120.  
  121.     virtual int rightValue( JSObject *_index, JSValue *_rv );
  122.  
  123. protected:
  124.     int kind;
  125.     JSWindowObject *object;
  126. };
  127.  
  128. class JSWindowVarObject : public JSVariableObject
  129. {
  130. public:
  131.     JSWindowVarObject( JSWindowObject *_win, int _kind );
  132.     virtual ~JSWindowVarObject();
  133.  
  134.     virtual JSObject *getValue();
  135.     virtual void setValue( JSObject* _val );
  136.     virtual void clear();
  137.  
  138. protected:
  139.     int kind;
  140.     JSWindowObject *object;
  141. };
  142.  
  143. class JSDocumentObject : public JSUserDefinedObject
  144. {
  145. public:
  146.     JSDocumentObject( JSWindowObject *_window );
  147.     virtual ~JSDocumentObject();
  148.  
  149.     virtual int isA() { return TYPE_JSDocumentObject; }    
  150.     virtual bool inherits( int _type )
  151.     { if ( _type == TYPE_JSDocumentObject ) return TRUE;
  152.     else return JSUserDefinedObject::inherits( _type ); }
  153.  
  154.     /**
  155.      * Never delete this instance.
  156.      */
  157.     virtual void release() { if ( lock > 1 ) lock--;  }
  158.  
  159.     JSWindowObject* getJSWindowObject() { return window; }
  160.     
  161. protected:
  162.     JSDocumentWriteFunction *jsDocumentWrite;
  163.     JSWindowObject *window;
  164. };
  165.  
  166. class JSDocumentWriteFunction : public JSFunction
  167. {
  168. public:
  169.     JSDocumentWriteFunction( JSDocumentObject *_obj );
  170.     virtual ~JSDocumentWriteFunction();
  171.     
  172.     virtual int rightValue( JSScopeStack* _s, JSValue *rv, JSParameterListObject *_param );
  173.  
  174. protected:
  175.     JSDocumentObject *object;
  176. };
  177.  
  178. class JSEnvironment
  179. {
  180. public:
  181.     JSEnvironment( KHTMLWidget *_view );
  182.     ~JSEnvironment();
  183.     
  184.     JSCode* parse( const char *_script );
  185.     int exec( JSCode *_code, JSInstanceScope *_scope = 0L );
  186.     
  187.     const char* readOutput() { return output.data(); }
  188.     void writeOutput( const char *_str ) { output += _str; }
  189.  
  190.     JSWindowObject* getJSWindowObject() { return jsWindowObject; }
  191.     KHTMLWidget* getKHTMLWidget() { return view; }
  192.     KHTMLView* getKHTMLView();
  193.     
  194. protected:
  195.     KHTMLWidget *view;
  196.     JSScope *globalScope;
  197.     
  198.     JSWindowObject *jsWindowObject;
  199.  
  200.     QString output;
  201. };
  202.  
  203. #endif
  204.